<!DOCTYPE doctype PUBLIC "-//W3C//DTD HTML 4.0 Frameset//EN">

<HTML>
  <HEAD>
    <META name="generator" content=
    "HTML Tidy for Java (vers. 2009-12-01), see jtidy.sourceforge.net">

    <TITLE>Exporting Files</TITLE>
    <LINK rel="stylesheet" type="text/css" href="help/shared/DefaultStyle.css">
  </HEAD>

  <BODY lang="EN-US">
    <H1><A name="Export"></A>Exporting Files</H1>

    <P>Ghidra provides an <I>Exporter</I> that allows a user to output program information into a
    file in various formats.&nbsp;</P>

    <P>Some of the formats the <I>Exporter</I> supports are:</P>
    <A name="Exporter_Formats">


    <UL>
      <LI><A href="#ascii">ASCII</A></LI>

      <LI><A href="#c_cpp">C/C++</A></LI>
      
      <LI><A href="#gzf">Ghidra Zip File (GZF)</A></LI>
      
      <LI><A href="#gdt">Ghidra Data Type Archive File (GDT)</a></LI>

      <LI><A href="#html">HTML</A></LI>

      <LI><A href="#intel_hex">Intel Hex</A></LI>
      
      <LI><A href="#original_file">Original File</A></LI>
      
      <LI><A href="#binary">Raw Bytes</A></LI>

      <LI><A href="#xml">XML Export Format</A></LI>

      <LI><A href="#sarif">SARIF Export Format</A></LI>
    </UL>

    <H2>Export Action</H2>

    <BLOCKQUOTE>
      <P>The export action can be invoked from the front-end project window or the CodeBrowser
      tool.</P>

      <H3>To export from the front-end project window:</H3>

      <BLOCKQUOTE>
        <H4>Steps:</H4>

        <UL>
          <LI>Right-click on the file to export in the tree.</LI>

          <LI>From the popup menu that appears, select the <B>Export...</B> menu item.</LI>

          <LI>Use the <A href="#Exporter_Dialog">Exporter Dialog</A> that appears to configure the
          export.</LI>

          <LI>Press the <B>OK</B> button to perform the export.</LI>
        </UL>
        
        <P><I><IMG src="help/shared/note.png"> In preparation for a file export, a selected project
        file may be opened in an attempt to support export formats that require an open
        file.  If the selected file requires an upgrade a warning dialog
        will be displayed and the affected export formats will not be available until an upgrade 
        is perfored, however a direct packed format of the project file may still be chosen
        without performing the upgrade first (e.g., <A href="#gzf">Ghidra Zip File (GZF)</A>,
        <A href="#gzf">Ghidra Zip File (GZF)</A>).
	  	</P>
	  
      </BLOCKQUOTE>

      <H3>To export from the CodeBrowser tool:</H3>

      <BLOCKQUOTE>
        <H4>Steps:</H4>

        <UL>
          <LI>Make sure the program to export is the currently open program in the CodeBrowser
          tool.</LI>

          <LI>Invoke the action from the <B>File<IMG src="help/shared/arrow.gif" alt="">Export
          File...</B> menu item.</LI>

          <LI>Use the <A href="#Exporter_Dialog">Exporter Dialog</A> that appears to configure the
          export.</LI>

          <LI>Press the <B>OK</B> button to perform the export.</LI>
        </UL>
      </BLOCKQUOTE>

      <H2>Export Dialog <A name="Exporter_Dialog"></A></H2>

      <BLOCKQUOTE>
        <P>The Export Dialog is used to configure the export of the chosen program.</P>

        <P align="center"><IMG src="images/Export_Dialog.png" alt=""></P>

        <H3>Dialog Fields</H3>

        <BLOCKQUOTE>
          <UL>
            <LI><B>Format</B> - This field is a drop-down list containing all the valid <A href=
            "#Exporter_Formats">export file formats</A> that could be used to to export the
            program. By default, the last used format will be auto-selected.</LI>

            <LI><B>Output File</B> - This field specifies the the output file for the export. By
            default, the output file's name will be the name of the program and the output folder
            will be the user's home folder or the last folder used for an export if an export has
            been performed in the current session. Use the "..." button to bring up a file chooser
            to change the output file.</LI>

            <LI><B>Selection Only</B> - If this checkbox is selected, then only the areas of the
            program that are in the current selection will be exported. Obviously, this only
            applies when exporting from an open program with a selection in the CodeBrowser tool
            and not when exporting from the front-end project window. Also, not all export formats
            support partial exports. The GZF format, for example, always exports the entire program
            since it is really just making an exported copy of the entire program database.</LI>

            <LI><B>Options...</B> - This button will pop up format specific options for the
            import.</LI>
          </UL>
        </BLOCKQUOTE>
      </BLOCKQUOTE>

      <H2>Exporters</H2>

      <BLOCKQUOTE>
        <H3><A name="ascii"/><A name="Options_Ascii"/>Ascii</H3>

        <BLOCKQUOTE>
          <P>Creates a plain text representation of the program's listing, similar to what is
          displayed in the <A href="help/topics/CodeBrowserPlugin/Browser_Field_Formatter.htm">Code
          Browser Field Format</A>.</P>

          <H4><A name="ascii_options"/>Ascii Options</H4>
        </BLOCKQUOTE>

        <DIV align="center">
          <IMG src="images/Ascii_Options.png" alt=""><BR>
        </DIV>

        <BLOCKQUOTE>
          <BLOCKQUOTE>
            <H4>Advanced</H4>

            <BLOCKQUOTE>
              <TABLE cellspacing="1" border="0" width="70%">
                <TBODY>
                  <TR>
                    <TD><I><B>Label Suffix</B></I><BR>
                    </TD>

                    <TD valign="top">the string to append on the end of labels<BR>
                    </TD>
                  </TR>

                  <TR>
                    <TD><I><B>Comment Prefix</B></I><BR>
                    </TD>

                    <TD valign="top">the string to prepend to the beginning of comments<BR>
                    </TD>
                  </TR>
                </TBODY>
              </TABLE>
            </BLOCKQUOTE>

            <H4>Show</H4>

            <BLOCKQUOTE>
              <P>The check-boxes in this panel are used to determine what program elements should
              be included in the output file. A selected check-box denotes that the corresponding
              element will be included in the file. The checkboxes for elements that are present in
              the program are selected by default.</P>

              <TABLE border="0" cellspacing="1" width="70%">
                <TBODY>
                  <TR>
                    <TD><I><B>Comments</B></I></TD>

                    <TD valign="top" align="left">Include <I>Pre</I>, <I>Post</I>, <I>EOL</I>, and
                    <I>Plate</I> comments</TD>
                  </TR>

                  <TR>
                    <TD><I><B>Properties</B></I></TD>

                    <TD valign="top" align="left">Include properties; e.g., <I>Bookmarks</I>,
                    <I>Spacers</I></TD>
                  </TR>

                  <TR>
                    <TD><I><B>Structures</B></I></TD>

                    <TD valign="top" align="left">Include <I>Structures</I> and <I>Unions</I>
                    defined on code units</TD>
                  </TR>

                  <TR>
                    <TD><I><B>Undefined Data</B></I></TD>

                    <TD valign="top" align="left">Include all undefined code units (e.g, "??") or
                    replace with "<I>[BYTES REMOVED]</I>" place-holder</TD>
                  </TR>

                  <TR>
                    <TD><I><B>Ref Headers</B></I></TD>

                    <TD valign="top" align="left">Include the cross reference header
                    <I>BACK[m,n]</I> or <I>FWD[m,n]:</I>, where <I>m</I> is the number of cross
                    references and <I>n</I> is the number of offcut cross reference; select the
                    <B><I>Back Refs</I></B> and/or <I><B>Forward Refs</B></I> for the
                    <I><B>Back/FWD</B></I> header to show up</TD>
                  </TR>

                  <TR>
                    <TD><I><B>Back Refs</B></I></TD>

                    <TD valign="top" align="left">Include the list of cross references for each
                    code unit</TD>
                  </TR>

                  <TR>
                    <TD><B><I>Forward Refs</I></B></TD>

                    <TD valign="top" align="left">Include the list of references to the mnemonic
                    for each code unit</TD>
                  </TR>

                  <TR>
                    <TD><I><B>Functions</B></I></TD>

                    <TD valign="top" align="left">Include signature and header for each
                    function</TD>
                  </TR>
                </TBODY>
              </TABLE>
            </BLOCKQUOTE>

            <H4>Width</H4>

            <BLOCKQUOTE>
              <P>The text-fields in this panel specify the width, in number of characters, to use
              when displaying program elements in the output file.</P>

              <P><IMG alt="" border="0" src="help/shared/note.png"> <I>Setting a width to zero (0)
              effectively excludes it from the output file.</I></P>
            </BLOCKQUOTE>
          </BLOCKQUOTE>
        </BLOCKQUOTE>

        <H3><A name="c_cpp"/><A name="Options_C_C__""/>C/C++</H3>

        <BLOCKQUOTE>
          <P>Create a C/C++ file containing functions decompiled from the program and, optionally,
          containing definitions of all datatypes from the program's
          <A href="help/topics/DataTypeManagerPlugin/data_type_manager_description.htm">
          data type manager</A>. The datatype definitions and a prototype declaration for each function
          can be placed in a separate header file.&nbsp;</P>

          <H4>C/C++ Options</H4>

          <P align="center"><IMG src="images/C_Options.png" alt=""></P>

          <UL>
            <LI><B>Create Header File (.h)</B> - Select to create a .h file.</LI>

            <LI><B>Create C File (.c)</B> - Select to create a .c file.</LI>

            <LI><B>Use C++ Style Comments (//)</B> - Select to use // or /* style comments.</LI>
            
            <LI><B>Emit Data-type Definitions</B> - Select to export a C/C++ definition for each data-type.</LI>
            
            <LI><B>Function Tags to Filter</B> - Optional list of function tags to filter which 
            functions are exported. Multiple tags must be comma separated.   Any tags listed will
            be considered a match for purposes of filtering.  The result of filtering, to include
            or exclude, depends on the <B>Function Tags Excluded/Included</B> setting.
            <U>If this list is empty, than all functions will be exported</U>.
            </LI>
            
            <LI><B>Function Tags Excluded/Included</B> - Select to exclude from export all 
            functions with a tag that matches any in the <B>Function Tags to Filter</B> list.   
            Deselect to include in export only functions with a tag that matches any in the list.
            </LI>
          </UL>
        </BLOCKQUOTE>

        <H3><A name="gzf"/>Ghidra Zip File (GZF)</H3>

        <BLOCKQUOTE>
          <P>Creates a GZF file from a Program in your project. You may want to create a GZF file
          so that you can give it to another user who can then <A href=
          "help/topics/ImporterPlugin/importer.htm">import</A> into their project.  A program
          export of this format from the Project Window will be based on the current saved file
          content and bypass any potential upgrade that may be required by other formats.
          </P>
        </BLOCKQUOTE>
        
        <H3><A name="gdt"/>Ghidra Data Type Archive File (GDT)</H3>

        <BLOCKQUOTE>
          <P>Creates a GDT file from a Data Type Archive in your project. You may want to create a GDT file
          so that you can give it to another user who can then <A href=
          "help/topics/ImporterPlugin/importer.htm">import</A> into their project or open directly
          via the Data Type Manager as a 
          <A href="help/topics/DataTypeManagerPlugin/data_type_manager_description.htm#Open_File_Data_Type_Archive">File Data Type Archive</A>.
          A project Data Type Archive export of this format from the Project Window will be based on 
          the current saved file content and bypass any potential upgrade that may be required by other formats.
          </P>
        </BLOCKQUOTE>

        <H3><A name="html"/><A name="Options_HTML"/>HTML</H3>

        <BLOCKQUOTE>
          <P>Creates a hyper-text representation of the program's listing, similar to what is
          displayed in the <A href="help/topics/CodeBrowserPlugin/Browser_Field_Formatter.htm">Code
          Browser Field Format</A>. The HTML output is analogous to the ASCII output, however HTML
          allows format and hyper-link information to be added to the file. The formatting allows
          fields to be color-matched to those in the Code Browser. The hyper-linking allows
          navigation similar to that supported in the Code Browser.</P>

          <P><I><IMG alt="" border="0" src="help/shared/note.png"> The HTML Options are identical
          the <A href="#ascii_options">ASCII Options</A>.</I></P>
        </BLOCKQUOTE>

        <H3><A name="intel_hex"/><A name="Options_Intel_Hex"/>Intel Hex</H3>

        <BLOCKQUOTE>
          <P>The Intel Hex format, a printable file representing memory images, was originally
          designed to program EPROM devices. The Intel Hex exporter creates files in this format
          which can be used to program these EPROM devices.</P>

          <H4>Intel Hex Options</H4>

          <P align="center"><IMG src="images/Intel_Hex_Options.png" alt=""></P>

          <UL>
            <LI><B>Address Space</B> - Specifies which address space to export as Intel Hex format
            only supports one address space. This option will be initialized to the "default"
            address space.</LI>
            <LI><B>Record Size</B> - Specifies the size (in bytes) of each record in the
            output file. The default 16.</LI>
            <LI><B>Align To Record Size</B> - If checked, this will ensure that <b>only</b> records matching
            the record size will be output. eg: if you set the record size to 16 but there are
            18 bytes selected, you will see only one line of 16 bytes in the output; the remaining
            2 bytes will be dropped.</LI>
          </UL>
        </BLOCKQUOTE>
        
        <H3><A name="original_file"/><A name="Options_Original_File"/>Original File</H3>

        <BLOCKQUOTE>
          <P>Writes a program back to its original file layout. By default, any file-backed bytes 
          that were modified by the user in the program database will be reflected in the new file.
          Optionally, the program can be written back to its unmodified file bytes, discarding all
          user modifications.
          </P>
          
          <H4>Original File Options</H4>

          <UL>
            <LI><B>Export User Byte Modifications</B> - If checked, user byte modifications are
            preserved in the exported file. If unchecked, no user byte modifications are preserved
            and the exported file will exactly match the file that was originally imported.</LI>
          </UL>
          <UL>
            <LI><B>Save Multiple File Sources To Directory</B> - If checked, the destination file 
            will be treated as a directory. Each file source from the program will be saved to this
            newly created directory with names of the form &lt;directory&gt;.0, &lt;directory&gt;.1,
            etc. If the program contains multiple file sources and this option is not checked, only 
            the primary (first) file source will saved to the specified destination file.</LI>
          </UL>
          
          <P><IMG alt="" border="0" src="help/shared/note.png"> <I>This exporter is only
          operational when the program has at least one file-backed byte source.  This will be 
          reflected in the <A href="help/topics/MemoryMapPlugin/Memory_Map.htm">Memory Map's</A> 
          Byte Source column, which entries that begin with <B>File:</B></I></P>

          <P><IMG alt="" border="0" src="help/shared/note.png"> <I>Writing back a modified Memory 
          Map is not supported. </I></P>
          
          <P><IMG alt="" border="0" src="help/shared/note.png"> <I>Relocation bytes are always
          restored to their original values, even if the user modifies them.</I></P>
          
          <P><IMG alt="" border="0" src="help/shared/warning.png"> <I>Programs written to disk with
          this exporter may be runnable on your native platform.  Use caution when exporting 
          potentially malicious programs.</I></P>
        </BLOCKQUOTE>
        
        <H3><A name="binary"/><A name="Options_Binary"/></A>Raw Bytes</H3>

        <BLOCKQUOTE>
          <P>Creates a binary file containing only the raw bytes from each memory block in the 
          program. If there are multiple memory blocks, their bytes will be concatenated in the 
          exported binary file.  If the program was originally created using the <B>Binary 
          Importer</B> and there is only one memory block, then this exporter allows recreation of 
          the original file.</P>

          <P><IMG alt="" border="0" src="help/shared/note.png"> <I>Only initialized memory blocks
          are included in the output file.</I></P>
        </BLOCKQUOTE>

        <H3><A name="xml"/><A name="Options_XML"/>XML</H3>

        <BLOCKQUOTE>
          <P>The XML Exporter creates XML files that conform to Ghidra's Program DTD. You can
          re-import files in this format using the <A href=
          "help/topics/ImporterPlugin/importer.htm">XML Importer</A>.</P>

          <P><A name="xml_options"></A> <I><IMG alt="" border="0" src="help/shared/note.png">The
          XML Options are identical the <A href=
          "help/topics/ImporterPlugin/importer.htm#xml_options">XML Importer Options</A>.</I></P>
        </BLOCKQUOTE>

        <H3><A name="sarif"/><A name="Options_SARIF"/>SARIF</H3>

        <BLOCKQUOTE>
          <P>The SARIF Exporter creates SARIF files that conform to Ghidra's Program DTD. You can
          re-import files in this format using the <A href=
          "help/topics/ImporterPlugin/importer.htm">SARIF Importer</A>.</P>

          <P><A name="sarif_options"></A> <I><IMG alt="" border="0" src="help/shared/note.png">The
          SARIF Options are identical the <A href=
          "help/topics/ImporterPlugin/importer.htm#sarif_options">SARIF Importer Options</A>.</I></P>
        </BLOCKQUOTE>
      </BLOCKQUOTE>

      <P class="relatedtopic">Related Topics:</P>

      <UL>
        <LI><A href="help/topics/ImporterPlugin/importer.htm">Importing Files</A></LI>
      </UL><BR>
    </BLOCKQUOTE>
  </BODY>
</HTML>
